var TVB = TVB || {};
TVB.Error = {};
TVB.Error['zh-hant-hk'] = {
  serverError : "服務器臨時故障",
  email: {
  "empty"       : "請輸入電郵地址！",
  "illegal"     : "電郵地址格式錯誤，請重新輸入！"
  },
  "pwd"         : {
  "illegal"     : "密碼最少為6個字符！",
  "block"		: "密碼不可使用空格！",
  "invalid"		: "密碼不可使用空格！",
  "notmatch"    : "密碼不一致，請重新輸入！"
  },
  "repwd"     : {
  "illegal"     : "請輸入正確密碼！",
  "notmatch"    : "請輸入正確密碼！"
  },
  "captcha"     : {
  "empty"       : "請輸入驗證碼",
  "notmatch"    : "驗證碼錯誤，請重新輸入！"
  },
  "agree_term"  : {
  "empty"       : "請確認已閱讀及同意協議條款。"
  },
  "card_type" : {
	 	"empty" : "請選擇信用卡類型"
  },
  "card_owner" : {
		"empty" : "請輸入持卡人姓名"  
  },
  "card_no" : {
		"empty" : "請輸入正確的信用卡號碼",
		"invalid" : "請提供正確的信用卡號碼"
  },
  "card_cvv" : {
 		"empty" : "請輸入正確的CVV/CVC"	  
 },
 "card_expiry" : {
		"empty" : "請選擇正確的有效日期"   
 }
};
TVB.Error['zh-hans-hk'] = {
  "serverError" : "服务器临时故障",
  "pwd"         : {
  "illegal"     : "密码最少为6个字符！",
  "block"		: "密码不可使用空格！",
  "invalid"		: "密码不可使用空格！",
  "notmatch"    : "密码不一致，请重新输入！"
  },
  "repwd"     : {
  "illegal"     : "请输入正确密码！",
  "notmatch"    : "请输入正确密码！"
  },
  "email"       : {
  "empty"       : "请输入电邮地址！",
  "illegal"     : "电邮地址格式错误，请重新输入！"
  },
  "captcha"     : {
  "empty"       : "请输入验证码",
  "notmatch"    : "验证码错误，请重新输入！"
  },
  "agree_term"  : {
  "empty"       : "请确认已阅读及同意协议条款。"
  },
  "card_type" : {
	 	"empty" : "请选择信用卡类型"
  },
  "card_owner" : {
		"empty" : "请输入持卡人姓名"  
  },
  "card_no" : {
		"empty" : "请输入正确的信用卡号码",
		"invalid" : "请提供正确的信用卡号码"
  },
  "card_cvv" : {
 		"empty" : "请输入正确的CVV/CVC"	  
 },
 "card_expiry" : {
		"empty" : "请选择正确的有效日期"   
 }
};
TVB.Error['en-hk'] = {
  "serverError" : "Internal Server Error",
  "pwd"         : {
  "illegal"     : "Password should be at least 6 characters!",
  "block"		: "Space is not allowed in Password!",
  "invalid"		: "Space is not allowed in Password!",
  "notmatch"    : "The passwords you entered do not match, please try again!"
  },
  "repwd"     : {
  "illegal"     : "Please enter your password correctly!",
  "notmatch"    : "Please enter your password correctly!"
  },
  "email"       : {
   "empty"       : "Please enter your email address!",
  "illegal"     : "Invalid email address, please try again!"
  },
  "captcha"     : {
  "empty"       : "This field is required.",
  "notmatch"    : "Verification Code mismatch, please try again!"
  },
  "agree_term"  : {
  "empty"       : "Please read and agree on our Terms and Conditions."
  },
  "card_type" : {
	 	"empty" : "Please enter Card Type"
  },
  "card_owner" : {
		"empty" : "Please enter Card Holder Name"  
  },
  "card_no" : {
		"empty" : "Please enter Card Number correctly",
		"invalid" : "Please provide correct credit card number"
  },
  "card_cvv" : {
 		"empty" : "Please enter CVV/CVC correctly"	  
 },
 "card_expiry" : {
		"empty" : "Please select Expiry Date correctly"   
 }
};
TVB.Mobile = {
	cardValid : function( cardNo ){
		var sum = 0, iNum, isok = false;
		var cValue = $(':input[name=card_type]:checked').val();
		var cardType = cValue ? cValue.toLowerCase() : '';	
		
		/*for( var i in cardNo+='' ){
		  iNum = parseInt(cardNo[i]);
		  sum += i%2?iNum:iNum>4?iNum*2%10+1:iNum*2;
		}*/
		
		//return !(sum%10) && isok;
		if(typeof $(':input[name=card_type]').get(0) != 'undefined' ) {
			if(cardType=='visa'){
				isok = /^4\d+$/.test(cardNo);
			}else if(cardType=='master'){
				isok = /^5\d+$/.test(cardNo);	
			}
			
		}else {
			isok = true;
		}	
		
		return this.mod10(cardNo) && isok;
  	},
	mod10 : function(ccNumb){
		var valid 	= "0123456789"
		var len 	= ccNumb.length;
		var bNum 	= true;
		var iCCN 	= ccNumb;
		var sCCN 	= ccNumb.toString();
		var iCCN;
		var iTotal 	= 0;
		var bResult = false;
		var digit;
		var temp;
		
		iCCN = sCCN.replace (/^\s+|\s+$/g,'');
		for (var j=0; j<len; j++) {
		temp = "" + iCCN.substring(j, j+1);
		if (valid.indexOf(temp) == "-1") bNum = false;
		}
		if(!bNum){bResult = false;}
			iCCN = parseInt(iCCN);
			
		if(len == 0){
			bResult = true;
		}else{
			if(len >= 15){
				for(var i=len;i>0;i--){
				digit = "digit" + i;
			
					calc = parseInt(iCCN) % 10;	
					calc = parseInt(calc);
		
					iTotal += calc;
						
					i--;
				digit = "digit" + i;				
					iCCN = iCCN / 10;
					calc = parseInt(iCCN) % 10 ;
					 calc2 = calc *2;
		
					switch(calc2){
						case 10: calc2 = 1; break;
						case 12: calc2 = 3; break;
						case 14: calc2 = 5; break;
						case 16: calc2 = 7; break;
						case 18: calc2 = 9; break;
						default: calc2 = calc2; 
					}
					iCCN = iCCN / 10;
					iTotal += calc2;				
				}
		
				if ((iTotal%10)==0){
					bResult = true;
				}else{
					bResult = false;
				}
			}
		}
		return bResult;
	},
	cardExpiryDate : function (y,m,adjust){
		return parseInt(y) <= new Date().getFullYear() ? parseInt(m,10) >= new Date().getMonth()+1+adjust : (parseInt(m)>0 ? true : false);
	}
};